package com.hemh.handler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**   
 * 
 * @author HeMingHui
 * @since 2020-10-29
 * @description 拦截器的配置
 */
public class ConfigPathInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, 
    		HttpServletResponse response, Object handler) throws Exception {
        System.out.println("----->>>请求："+request.getRequestURI());
        /** 不拦截get类别的请求 */
		/*
		 * if(request.getMethod().equalsIgnoreCase("GET"))
		 * { 
		 * 	return true; 
		 * }
		 */
        //return false;
        
        
		/** 通过session判断是否拦截，可用于token判断(token可以自动生成+使用jwt)*/
		 /** HttpSession session=request.getSession();
		 * if(null!=session.getAttribute("admin")) 
		 * 	return true; 
		 * return false;
		 */
        
        return true;
        
        
    }
    
    /** 访问controller之后 访问视图之前被调用*/    
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
 
    }
 
    /** 访问视图之后被调用 */ 
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
 
    }
}